/**
 * 声音控制器
 */
class SoundControl {
	//声道
	private static sound_channel_list:Array<egret.SoundChannel>;
	//音量
	private static volume:number=1;

	public static init():void{
		SoundControl.sound_channel_list=new Array<egret.SoundChannel>();
	}

	//播放声音
	public static play(name:string,bg:Boolean=false):void{
		let sound:egret.Sound=RES.getRes(name);
		let sc:egret.SoundChannel=bg?sound.play(0,-1):sound.play(0,1);
		sc.volume=SoundControl.volume;
		let arr:Array<egret.SoundChannel>=SoundControl.sound_channel_list;
		for(let i=0;i<arr.length;i++){
			if(!arr[i]){
				arr[i]=sc;
				return;
			}
		}
		SoundControl.sound_channel_list.push(sc);
	}
	//控制音量
	public static setVolume(value:number):void{
		SoundControl.volume=value;
		if(SoundControl.sound_channel_list==undefined)return;
		let arr:Array<egret.SoundChannel>=SoundControl.sound_channel_list;
		for(let i=0;i<arr.length;i++){
			let sc:egret.SoundChannel=arr[i];
			if(sc){
				try{
					sc.volume=value;
				}catch(e){

				}
			}
		}
	}
	public constructor() {
	}
}